﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

using Pg.BioMedics.SDR.Entities;
using Pg.BioMedics.SDR.Entities.Codes;
using Pg.BioMedics.SDR.Services;
using Pg.BioMedics.SDR.Web.Controls;
using Pg.BioMedics.SDR.Web.Constants;

public partial class Operations_Views_RegisterDocumentView : BaseHostedView
{
    #region Fields

    private IIndexingService indexingService;
    private Document document = new Document();

    #endregion

    #region Properties

    /// <summary>
    /// Sets instance of indexing service. This property is utilized by IoC context 
    /// for supplying instance of IndexingService to this view
    /// </summary>
    public IIndexingService IndexingService
    {
        set
        {
            this.indexingService = value;
        }
    }

    /// <summary>
    /// Gets document model
    /// </summary>
    public Document Document
    {
        get
        {
            return this.document;
        }
    }

    #endregion

    #region Event handlers

    protected void registerLinkButton_Click(object sender, EventArgs e)
    {
        try
        {
            // unbind form data and get file content
            base.UnbindFormData();

            this.document = this.indexingService.RegisterDocument(this.document.Title,
                                                                  this.document.Description,
                                                                  fileUpload.UploadedFile.FileName,
                                                                  fileUpload.UploadedFile.Location,
                                                                  Page.User.Identity.Name);

            // navigate to 
            base.Navigate(DocumentsViews.FinishRegisterDocumentView, DocumentsViews.RegisterDocumentView, this.document);
        }
        catch (Exception ex)
        {
            base.Navigate(DocumentsViews.ErrorView, ex);
        }
        finally
        {
            fileUpload.Clean();
        }
    }

    #endregion
}
